package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaisengit.enity.Company;

import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class CompanyDao {

	private DBHelp <Company> db = new DBHelp<Company>();

	public Company findByname(String compyname) {
		

		
			String sql = "select id ,name from t_company where name = ? ";
			
			return db.executeQueryForObject( sql, new CompanyRowMapper(), compyname);
		
		
	}

	public void save(Company company) {
		String sql = "insert into t_company (id,name) values (?,?)";
		db.executeSQL(sql, company.getId(),company.getName());
		
	}
	
	private class CompanyRowMapper implements RowMapper<Company>{
			
			public Company mapperRow (ResultSet rs) throws SQLException{
				
				Company company = new Company();
				company.setId(rs.getString("id"));
				company.setName(rs.getString("name"));
				
				return company;
				
				
			}
		}

}
